package huaweiod.first;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * 华为OD机试真题 Java 实现【羊、狼、农夫过河】【2022.11 Q4新题】
 */
public class A_2023_11_SheepWolfBoat {

    public static int process(int m0, int n0, int x, int m1, int n1, int time) {
        if (m0 + n0 <= x) {
//            if (time + 1 < ans) {
//                ans = time + 1;
//            }
            return time + 1;
        }
        // 羊
        for (int i = 0; i <= m0; i++) {
            // 狼
            for (int j = 0; j <= n0 && i + j <= x; j++) {
                if (i + j == 0) {
                    continue;
                }
                if ((m0 - i == 0 || m0 - i > n0 - j) && (m1 + i == 0 || m1 + i > n1 + j)) {
                    int process = process(m0 - i, n0 - j, x, m1 + i, n1 + j, time + 1);
                    if (process != -1 && process < ans) {
                        ans = process;
                    }
                }
            }
        }
        return -1;
    }

    public static int ans;

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        //转为数组
        List<Integer> nums = Arrays.stream(in.nextLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        int M = nums.get(0);
        int N = nums.get(1);
        int X = nums.get(2);

        ans = (N + M) * X;
        if (N >= M) {
            System.out.println("0");
        } else {
            int process = process(M, N, X, 0, 0, 0);
            if (ans == (N + M) * X) {
                System.out.println("0");
            } else {
                System.out.println(ans);
            }
        }
    }
}
